package com.sykj.servies.impl;

import com.sykj.dao.CustomerDao;
import com.sykj.pojo.Customer;
import com.sykj.pojo.CustomerExample;
import com.sykj.servies.CustomerServies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CustomerServiesImpl implements CustomerServies{

    @Autowired
    CustomerDao customerDao;
    //查询用户到后台
    @Override
    public List<Customer> list() {
        return customerDao.selectByExample(null);
    }

    //通过状态修改是否为会员
    @Override
    public void shezhihuiyuan(int id) {
        customerDao.enableStatus(id);
    }

    @Override
    public Customer foreLogin(Customer customer) {
        CustomerExample example = new CustomerExample();
        example.createCriteria().andNameEqualTo(customer.getName()).andPasswordEqualTo(customer.getPassword());
        List<Customer> customers = customerDao.selectByExample(example);

        return customers.size()>0?customers.get(0):null;
    }

    @Override
    public void save(Customer entity) {
        customerDao.insert(entity);
    }
    //通过公共crud方法，根据id删除
    @Override
    public void del(int id) {
        customerDao.deleteByPrimaryKey(id);
    }

    @Override
    public Customer get(int id) {
        return customerDao.selectByPrimaryKey(id);
    }
}
